In [60]:
print('1. 분석 목적 : 학생의 성적에 영향을 주는 여러 변수들간의 관계 파악 (종속변수 : 성적)')
print('2. 프로젝트 목적 : 목적 달성을 위해 적합한 데이터를 선정 및 python으로 불러들인 후, 정제하고 데이터를 핸들링하는 역량을 함양하는 것.')
1. 분석 목적 : 학생의 성적에 영향을 주는 여러 변수들간의 관계 파악 (종속변수 : 성적) 2. 프로젝트 목적 : 목적 달성을 위해 적합한 데이터를 선정 및 python으로 불러들인 후, 정제하고 데이터를 핸들링하는 역량을 함양하는 것.
In [62]:
# 데이터 불러들이기
import pandas as pd
data = pd.read_csv('StudentPerformanceFactors.csv')
In [64]:
# 데이터를 간략하게 탐색하기
data.head(5)
Out[64]:
| Hours_Studied | Attendance | Parental_Involvement | Access_to_Resources | Extracurricular_Activities | Sleep_Hours | Previous_Scores | Motivation_Level | Internet_Access | Tutoring_Sessions | Family_Income | Teacher_Quality | School_Type | Peer_Influence | Physical_Activity | Learning_Disabilities | Parental_Education_Level | Distance_from_Home | Gender | Exam_Score | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 23 | 84 | Low | High | No | 7 | 73 | Low | Yes | 0 | Low | Medium | Public | Positive | 3 | No | High School | Near | Male | 67 |
| 1 | 19 | 64 | Low | Medium | No | 8 | 59 | Low | Yes | 2 | Medium | Medium | Public | Negative | 4 | No | College | Moderate | Female | 61 |
| 2 | 24 | 98 | Medium | Medium | Yes | 7 | 91 | Medium | Yes | 2 | Medium | Medium | Public | Neutral | 4 | No | Postgraduate | Near | Male | 74 |
| 3 | 29 | 89 | Low | Medium | Yes | 8 | 98 | Medium | Yes | 1 | Medium | Medium | Public | Negative | 4 | No | High School | Moderate | Male | 71 |
| 4 | 19 | 92 | Medium | Medium | Yes | 6 | 65 | Medium | Yes | 3 | Medium | High | Public | Neutral | 4 | No | College | Near | Female | 70 |
In [16]:
import ydata_profiling
from ydata_profiling import ProfileReport
pr = ProfileReport(data)
pr
Summarize dataset: 0%| | 0/5 [00:00<?, ?it/s]
Generate report structure: 0%| | 0/1 [00:00<?, ?it/s]
Render HTML: 0%| | 0/1 [00:00<?, ?it/s]
Out[16]:
In [66]:
# ydata-profiling으로 탐색을 했을 때,
# 중복값 : 없음
# 결측값 : 있음 - Teacher_Quality(78개) / Perental_Education_Level(90개) / Distance_from_Home(67개)
# 각각의 결측값의 비율이 1% 초반이므로 무시해도 될만한 수치라고 판단하여 결측값은 모두 삭제
data = data.dropna()
data.count()
Out[66]:
Hours_Studied 6378 Attendance 6378 Parental_Involvement 6378 Access_to_Resources 6378 Extracurricular_Activities 6378 Sleep_Hours 6378 Previous_Scores 6378 Motivation_Level 6378 Internet_Access 6378 Tutoring_Sessions 6378 Family_Income 6378 Teacher_Quality 6378 School_Type 6378 Peer_Influence 6378 Physical_Activity 6378 Learning_Disabilities 6378 Parental_Education_Level 6378 Distance_from_Home 6378 Gender 6378 Exam_Score 6378 dtype: int64
In [28]:
# IQR 방식을 활용하여 이상치 제거 후 clear_data로 다시 할당
import seaborn as sns
import matplotlib.pyplot as plt
Q1 = data.quantile(0.25, numeric_only = True)
Q3 = data.quantile(0.75, numeric_only = True)
IQR = Q3 - Q1
print(IQR)
data, IQR = data.align(IQR, axis = 1)
clear_data = data[~((data < (Q1 - 1.5*IQR))|(data > (Q3 + 1.5*IQR))).any(axis=1)]
Hours_Studied 8.0 Attendance 20.0 Sleep_Hours 2.0 Previous_Scores 25.0 Tutoring_Sessions 1.0 Physical_Activity 2.0 Exam_Score 4.0 dtype: float64
In [30]:
# 정제된 DATA(clear_data)에 대하여 다시 profileReport를 실행하여 상관관계 분석.
pr = ProfileReport(clear_data)
pr
Summarize dataset: 0%| | 0/5 [00:00<?, ?it/s]
Generate report structure: 0%| | 0/1 [00:00<?, ?it/s]
Render HTML: 0%| | 0/1 [00:00<?, ?it/s]
Out[30]:
In [68]:
print()
print('분석 결과 : Exam_Score와 가장 상관관계가 높은 변수는 Attendance(수업참여율)과 Hours_Studied(공부시간)이며, \
그 외에도 Previous_Scores(이전시험성적)가 그나마 상관관계가 있다고 볼 수 있다.')
print()
print('-------------------------------------------------------------------------------------------------')
print('회고 : 대체로 다 알고 있는 당연한 결과가 나와서 특별한 인사이트를 얻지는 못하였음. \
그러나, 직접 데이터를 선정하고 정제하고 핸들링하는 경험을 통해, 데이터를 다루는 역량을 함양할 수 있었음.')
print()
분석 결과 : Exam_Score와 가장 상관관계가 높은 변수는 Attendance(수업참여율)과 Hours_Studied(공부시간)이며, 그 외에도 Previous_Scores(이전시험성적)가 그나마 상관관계가 있다고 볼 수 있다. ------------------------------------------------------------------------------------------------- 회고 : 대체로 다 알고 있는 당연한 결과가 나와서 특별한 인사이트를 얻지는 못하였음. 그러나, 직접 데이터를 선정하고 정제하고 핸들링하는 경험을 통해, 데이터를 다루는 역량을 함양할 수 있었음.